<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>获取URL中的参数方法 | 逆流时光~</title><meta name="keywords" content="spring,Java,接收参数"><meta name="author" content="FantasticCode,1443996278@qq.com"><meta name="copyright" content="FantasticCode"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1. 服务端获取前端传过来的参数的方法 1.1 直接把表单的参数写在Controller相应的方法的形参中，适用于get方式提交，不适用于post方式提交。 123456789101112&#x2F;**   * 1.直接把表单的参数写在Controller相应的方法的形参中   * @param username   * @param password   * @return   *&#x2F;  @Request">
<meta property="og:type" content="article">
<meta property="og:title" content="获取URL中的参数方法">
<meta property="og:url" content="https://yyj_challenged.gitee.io/2020/12/15/%E8%8E%B7%E5%8F%96URL%E4%B8%AD%E5%8F%82%E6%95%B0%E6%96%B9%E6%B3%95/index.html">
<meta property="og:site_name" content="逆流时光~">
<meta property="og:description" content="1. 服务端获取前端传过来的参数的方法 1.1 直接把表单的参数写在Controller相应的方法的形参中，适用于get方式提交，不适用于post方式提交。 123456789101112&#x2F;**   * 1.直接把表单的参数写在Controller相应的方法的形参中   * @param username   * @param password   * @return   *&#x2F;  @Request">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg11.jpg">
<meta property="article:published_time" content="2020-12-14T16:00:00.000Z">
<meta property="article:modified_time" content="2022-05-30T07:08:52.753Z">
<meta property="article:author" content="FantasticCode">
<meta property="article:tag" content="spring">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="接收参数">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg11.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://yyj_challenged.gitee.io/2020/12/15/%E8%8E%B7%E5%8F%96URL%E4%B8%AD%E5%8F%82%E6%95%B0%E6%96%B9%E6%B3%95/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="manifest" href="/img/pwa/manifest.json"/><link rel="apple-touch-icon" sizes="180x180" href="/img/pwa/apple-touch-icon.png"/><link rel="icon" type="image/png" sizes="32x32" href="/img/pwa/32.png"/><link rel="icon" type="image/png" sizes="16x16" href="/img/pwa/16.png"/><link rel="mask-icon" href="/img/pwa/safari-pinned-tab.svg" color="#5bbad5"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?67fada177b615329655b957d30519c62";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: {"appId":"UVE3L335VP","apiKey":"5c662b130a966e23356d9dd1739405cd","indexName":"dev_myblog","hits":{"per_page":6},"languages":{"input_placeholder":"搜索文章","hits_empty":"找不到您查询的内容：${query}","hits_stats":"找到 ${hits} 条结果，用时 ${time} 毫秒"}},
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: FantasticCode","link":"链接: ","source":"来源: 逆流时光~","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isAnchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '获取URL中的参数方法',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-05-30 15:08:52'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/atom.xml" title="逆流时光~" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">20</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">32</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 娱乐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/%E9%9F%B3%E4%B9%90"><i class="fa-fw /music/"></i><span> 0</span></a></li><li><a class="site-page child" href="/%E5%9B%BE%E7%89%87"><i class="fa-fw /picture/"></i><span> 1</span></a></li><li><a class="site-page child" href="/%E7%94%B5%E5%BD%B1"><i class="fa-fw /movie/"></i><span> 2</span></a></li><li><a class="site-page child" href="/%E4%B9%A6%E7%B1%8D"><i class="fa-fw /books/"></i><span> 3</span></a></li><li><a class="site-page child" href="/%E6%B8%B8%E6%88%8F"><i class="fa-fw /game/"></i><span> 4</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/treasure/"><i class="fa-fw fas fa-link"></i><span> 宝藏</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg11.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">逆流时光~</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 娱乐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/%E9%9F%B3%E4%B9%90"><i class="fa-fw /music/"></i><span> 0</span></a></li><li><a class="site-page child" href="/%E5%9B%BE%E7%89%87"><i class="fa-fw /picture/"></i><span> 1</span></a></li><li><a class="site-page child" href="/%E7%94%B5%E5%BD%B1"><i class="fa-fw /movie/"></i><span> 2</span></a></li><li><a class="site-page child" href="/%E4%B9%A6%E7%B1%8D"><i class="fa-fw /books/"></i><span> 3</span></a></li><li><a class="site-page child" href="/%E6%B8%B8%E6%88%8F"><i class="fa-fw /game/"></i><span> 4</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/treasure/"><i class="fa-fw fas fa-link"></i><span> 宝藏</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">获取URL中的参数方法</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-12-14T16:00:00.000Z" title="发表于 2020-12-15 00:00:00">2020-12-15</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-05-30T07:08:52.753Z" title="更新于 2022-05-30 15:08:52">2022-05-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Develop/">Develop</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>5分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="获取URL中的参数方法"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h4 id="1-服务端获取前端传过来的参数的方法">1. 服务端获取前端传过来的参数的方法</h4>
<h5 id="1-1-直接把表单的参数写在Controller相应的方法的形参中，适用于get方式提交，不适用于post方式提交。">1.1 直接把表单的参数写在Controller相应的方法的形参中，适用于get方式提交，不适用于post方式提交。</h5>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 1.直接把表单的参数写在Controller相应的方法的形参中</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> username</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> password</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@RequestMapping(&quot;/addUser1&quot;)</span></span><br><span class="line">  <span class="keyword">public</span> String <span class="title function_">addUser1</span><span class="params">(String username,String password)</span> &#123;</span><br><span class="line">      System.out.println(<span class="string">&quot;username is:&quot;</span>+username);</span><br><span class="line">      System.out.println(<span class="string">&quot;password is:&quot;</span>+password);</span><br><span class="line">      <span class="keyword">return</span> <span class="string">&quot;demo/index&quot;</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<p>我的url形式：<a target="_blank" rel="noopener" href="http://localhost/student/demo/addUser1?username=xiaoming&amp;password=123456">http://localhost/student/demo/addUser1?username=xiaoming&amp;password=123456</a></p>
<p>注意：提交的参数需要和Controller方法中的入参名称一致。</p>
<h5 id="1-2-通过HttpServletRequest接收，post方式和get方式都可以。">1.2 通过HttpServletRequest接收，post方式和get方式都可以。</h5>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 2、通过HttpServletRequest接收</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> request</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@RequestMapping(&quot;/addUser2&quot;)</span></span><br><span class="line">  <span class="keyword">public</span> String <span class="title function_">addUser2</span><span class="params">(HttpServletRequest request)</span> &#123;</span><br><span class="line">      String username=request.getParameter(<span class="string">&quot;username&quot;</span>);</span><br><span class="line">      String password=request.getParameter(<span class="string">&quot;password&quot;</span>);</span><br><span class="line">      System.out.println(<span class="string">&quot;username is:&quot;</span>+username);</span><br><span class="line">      System.out.println(<span class="string">&quot;password is:&quot;</span>+password);</span><br><span class="line">      <span class="keyword">return</span> <span class="string">&quot;demo/index&quot;</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h5 id="1-3-通过一个bean来接收-post方式和get方式都可以。">1.3 通过一个bean来接收,post方式和get方式都可以。</h5>
<ul>
<li>建立一个和表单中参数对应的bean</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> demo.model;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UserModel</span> &#123;</span><br><span class="line">    <span class="keyword">private</span> String username;</span><br><span class="line">    <span class="keyword">private</span> String password;</span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getUsername</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> username;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setUsername</span><span class="params">(String username)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.username = username;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> String <span class="title function_">getPassword</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> password;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setPassword</span><span class="params">(String password)</span> &#123;</span><br><span class="line">        <span class="built_in">this</span>.password = password;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>用这个bean来封装接收的参数</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 3、通过一个bean来接收</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> user</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@RequestMapping(&quot;/addUser3&quot;)</span></span><br><span class="line">  <span class="keyword">public</span> String <span class="title function_">addUser3</span><span class="params">(UserModel user)</span> &#123;</span><br><span class="line">      System.out.println(<span class="string">&quot;username is:&quot;</span>+user.getUsername());</span><br><span class="line">      System.out.println(<span class="string">&quot;password is:&quot;</span>+user.getPassword());</span><br><span class="line">      <span class="keyword">return</span> <span class="string">&quot;demo/index&quot;</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h5 id="1-4-通过-PathVariable获取路径中的参数">1.4 通过@PathVariable获取路径中的参数</h5>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 4、通过<span class="doctag">@PathVariable</span>获取路径中的参数</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> username</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param</span> password</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RequestMapping(value=&quot;/addUser4/&#123;username&#125;/&#123;password&#125;&quot;,method=RequestMethod.GET)</span></span><br><span class="line"><span class="keyword">public</span> String <span class="title function_">addUser4</span><span class="params">(<span class="meta">@PathVariable</span> String username,<span class="meta">@PathVariable</span> String password)</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;username is:&quot;</span>+username);</span><br><span class="line">        System.out.println(<span class="string">&quot;password is:&quot;</span>+password);</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;demo/index&quot;</span>;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>我的URL形式：<a target="_blank" rel="noopener" href="http://localhost/SSMDemo/demo/addUser4/xiaoming/123456%EF%BC%8C%E5%88%99%E8%87%AA%E5%8A%A8%E5%B0%86URL%E4%B8%AD%E6%A8%A1%E6%9D%BF%E5%8F%98%E9%87%8F%7Busername%7D%E5%92%8C%7Bpassword%7D%E7%BB%91%E5%AE%9A%E5%88%B0%E9%80%9A%E8%BF%87@PathVariable%E6%B3%A8%E8%A7%A3%E7%9A%84%E5%90%8C%E5%90%8D%E5%8F%82%E6%95%B0%E4%B8%8A%EF%BC%8C%E5%8D%B3%E5%85%A5%E5%8F%82%E5%90%8Eusername=xiaoming%E3%80%81password=123456%E3%80%82">http://localhost/SSMDemo/demo/addUser4/xiaoming/123456，则自动将URL中模板变量{username}和{password}绑定到通过@PathVariable注解的同名参数上，即入参后username=xiaoming、password=123456。</a></p>
<h5 id="1-5-使用-ModelAttribute注解获取POST请求的FORM表单数据">1.5 使用@ModelAttribute注解获取POST请求的FORM表单数据</h5>
<ul>
<li>JSP表单如下</li>
</ul>
<figure class="highlight jsp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;<span class="type">form</span> <span class="variable">action</span> <span class="operator">=</span><span class="string">&quot;&lt;%=request.getContextPath()%&gt;/demo/addUser5&quot;</span> method=<span class="string">&quot;post&quot;</span>&gt; </span><br><span class="line">     用户名:&amp;nbsp;&lt;input type=<span class="string">&quot;text&quot;</span> name=<span class="string">&quot;username&quot;</span>/&gt;&lt;br/&gt;</span><br><span class="line">     密&amp;nbsp;&amp;nbsp;码:&amp;nbsp;&lt;input type=<span class="string">&quot;password&quot;</span> name=<span class="string">&quot;password&quot;</span>/&gt;&lt;br/&gt;</span><br><span class="line">     &lt;input type=<span class="string">&quot;submit&quot;</span> value=<span class="string">&quot;提交&quot;</span>/&gt; </span><br><span class="line">     &lt;input type=<span class="string">&quot;reset&quot;</span> value=<span class="string">&quot;重置&quot;</span>/&gt; </span><br></pre></td></tr></table></figure>
<ul>
<li>controller层代码</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 5、使用<span class="doctag">@ModelAttribute</span>注解获取POST请求的FORM表单数据</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> user</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@RequestMapping(value=&quot;/addUser5&quot;,method=RequestMethod.POST)</span></span><br><span class="line">  <span class="keyword">public</span> String <span class="title function_">addUser5</span><span class="params">(<span class="meta">@ModelAttribute(&quot;user&quot;)</span> UserModel user)</span> &#123;</span><br><span class="line">      System.out.println(<span class="string">&quot;username is:&quot;</span>+user.getUsername());</span><br><span class="line">      System.out.println(<span class="string">&quot;password is:&quot;</span>+user.getPassword());</span><br><span class="line">      <span class="keyword">return</span> <span class="string">&quot;demo/index&quot;</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h5 id="1-6-用注解-RequestParam绑定请求参数到方法入参">1.6 用注解@RequestParam绑定请求参数到方法入参</h5>
<p>当请求参数username不存在时会有异常发生,可以通过设置属性required=false解决,例如: @RequestParam(value=“username”, required=false)</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 6、用注解<span class="doctag">@RequestParam</span>绑定请求参数到方法入参</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> username</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> password</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@RequestMapping(value=&quot;/addUser6&quot;,method=RequestMethod.GET)</span></span><br><span class="line">  <span class="keyword">public</span> String <span class="title function_">addUser6</span><span class="params">(<span class="meta">@RequestParam(&quot;username&quot;)</span> String username,</span></span><br><span class="line"><span class="params">                         <span class="meta">@RequestParam(&quot;password&quot;)</span> String password)</span> &#123;</span><br><span class="line">      System.out.println(<span class="string">&quot;username is:&quot;</span>+username);</span><br><span class="line">      System.out.println(<span class="string">&quot;password is:&quot;</span>+password);</span><br><span class="line">      <span class="keyword">return</span> <span class="string">&quot;demo/index&quot;</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h5 id="1-7-用注解-RequestBody绑定请求参数到方法入参-用于POST请求">1.7 用注解@RequestBody绑定请求参数到方法入参 用于POST请求</h5>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 7、用注解<span class="doctag">@Requestbody</span>绑定请求参数到方法入参</span></span><br><span class="line"><span class="comment">   * UserDTO 这个类为一个实体类，里面定义的属性与URL传过来的属性名一一对应。</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> username</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> password</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="meta">@RequestMapping(value=&quot;/addUser6&quot;,method=RequestMethod.POST)</span></span><br><span class="line">  <span class="keyword">public</span> String <span class="title function_">addUser6</span><span class="params">(<span class="meta">@RequestBody</span> UserDTO userDTO)</span> &#123;</span><br><span class="line">      System.out.println(<span class="string">&quot;username is:&quot;</span>+userDTO.getUserName());</span><br><span class="line">      System.out.println(<span class="string">&quot;password is:&quot;</span>+userDTO.getPassWord());</span><br><span class="line">      <span class="keyword">return</span> <span class="string">&quot;demo/index&quot;</span>;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h4 id="2-spring-boot的-RequestParam和-RequestBody的区别">2. spring boot的@RequestParam和@RequestBody的区别</h4>
<ul>
<li>问题描述：由于项目是前后端分离，因此后台使用的是spring boot，做成微服务，只暴露接口。接口设计风格为restful的风格，在get请求下，后台接收参数的注解为RequestBody时会报错；在 post请求下，后台接收参数的注解为RequestParam时也会报错。</li>
<li>问题原因：由于spring的RequestParam注解接收的参数是来自于requestHeader中，即请求头，也就是在url中，格式为xxx?username=123&amp;password=456，而RequestBody注解接收的参数则是来自于requestBody中，即请求体中。</li>
<li>解决方法：因此综上所述，如果为get请求时，后台接收参数的注解应该为RequestParam，如果为post请求时，则后台接收参数的注解就是为RequestBody。</li>
</ul>
<p><img src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/spring/006.png" alt=""></p>
<p><img src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/spring/007.png" alt=""></p>
<ul>
<li>另外，还有一种应用场景，接口规范为resultful风格时，举个例子：如果要获取某个id下此条问题答案的查询次数的话，则后台就需要动态获取参数， 其注解为@PathVariable，并且requestMapping中的value应为value=“/{id}/queryNum”</li>
</ul>
<p><img src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/spring/008.png" alt=""></p>
<h4 id="3-SpringBoot-中常用注解-PathVaribale-RequestParam-GetMapping介绍">3. SpringBoot 中常用注解@PathVaribale/@RequestParam/@GetMapping介绍</h4>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://yyj_challenged.gitee.io">FantasticCode</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://yyj_challenged.gitee.io/2020/12/15/%E8%8E%B7%E5%8F%96URL%E4%B8%AD%E5%8F%82%E6%95%B0%E6%96%B9%E6%B3%95/">https://yyj_challenged.gitee.io/2020/12/15/%E8%8E%B7%E5%8F%96URL%E4%B8%AD%E5%8F%82%E6%95%B0%E6%96%B9%E6%B3%95/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://yyj_challenged.gitee.io" target="_blank">逆流时光~</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/spring/">spring</a><a class="post-meta__tags" href="/tags/Java/">Java</a><a class="post-meta__tags" href="/tags/%E6%8E%A5%E6%94%B6%E5%8F%82%E6%95%B0/">接收参数</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg11.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/gh/overtrue/share.js@master/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/12/13/LeetCode219%E5%9C%BA/"><img class="prev-cover" src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg9.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">LeetCode219场比赛</div></div></a></div><div class="next-post pull-right"><a href="/2020/12/15/%E6%97%A5%E5%BF%97%E5%AE%9A%E6%9C%9F%E6%B8%85%E7%90%86/"><img class="next-cover" src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg18.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">日志定期清理</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2020/12/15/AOP/" title="AOP学习"><img class="cover" src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg10.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-12-15</div><div class="title">AOP学习</div></div></a></div><div><a href="/2020/12/15/shiro%E6%A1%86%E6%9E%B6/" title="shiro框架讲解"><img class="cover" src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg12.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-12-15</div><div class="title">shiro框架讲解</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="gitalk-container"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">FantasticCode</div><div class="author-info__description">铅华洗尽,一缕芳华</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">20</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">32</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">6</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/FantasticCode2019" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://leetcode.cn/u/fantastic_code2018" target="_blank" title="leetcode"><i class="fa-duotone fa-code"></i></a><a class="social-icon" href="mailto:1443996278Yao@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://space.bilibili.com/168589693" target="_blank" title="bilibili"><i class="fa-brands fa-bilibili"></i></a><a class="social-icon" href="https://blog.csdn.net/qq_36662611" target="_blank" title="CSDN"><i class="fa-solid fa-c"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E6%9C%8D%E5%8A%A1%E7%AB%AF%E8%8E%B7%E5%8F%96%E5%89%8D%E7%AB%AF%E4%BC%A0%E8%BF%87%E6%9D%A5%E7%9A%84%E5%8F%82%E6%95%B0%E7%9A%84%E6%96%B9%E6%B3%95"><span class="toc-number">1.</span> <span class="toc-text">1. 服务端获取前端传过来的参数的方法</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-1-%E7%9B%B4%E6%8E%A5%E6%8A%8A%E8%A1%A8%E5%8D%95%E7%9A%84%E5%8F%82%E6%95%B0%E5%86%99%E5%9C%A8Controller%E7%9B%B8%E5%BA%94%E7%9A%84%E6%96%B9%E6%B3%95%E7%9A%84%E5%BD%A2%E5%8F%82%E4%B8%AD%EF%BC%8C%E9%80%82%E7%94%A8%E4%BA%8Eget%E6%96%B9%E5%BC%8F%E6%8F%90%E4%BA%A4%EF%BC%8C%E4%B8%8D%E9%80%82%E7%94%A8%E4%BA%8Epost%E6%96%B9%E5%BC%8F%E6%8F%90%E4%BA%A4%E3%80%82"><span class="toc-number">1.1.</span> <span class="toc-text">1.1 直接把表单的参数写在Controller相应的方法的形参中，适用于get方式提交，不适用于post方式提交。</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-2-%E9%80%9A%E8%BF%87HttpServletRequest%E6%8E%A5%E6%94%B6%EF%BC%8Cpost%E6%96%B9%E5%BC%8F%E5%92%8Cget%E6%96%B9%E5%BC%8F%E9%83%BD%E5%8F%AF%E4%BB%A5%E3%80%82"><span class="toc-number">1.2.</span> <span class="toc-text">1.2 通过HttpServletRequest接收，post方式和get方式都可以。</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-3-%E9%80%9A%E8%BF%87%E4%B8%80%E4%B8%AAbean%E6%9D%A5%E6%8E%A5%E6%94%B6-post%E6%96%B9%E5%BC%8F%E5%92%8Cget%E6%96%B9%E5%BC%8F%E9%83%BD%E5%8F%AF%E4%BB%A5%E3%80%82"><span class="toc-number">1.3.</span> <span class="toc-text">1.3 通过一个bean来接收,post方式和get方式都可以。</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-4-%E9%80%9A%E8%BF%87-PathVariable%E8%8E%B7%E5%8F%96%E8%B7%AF%E5%BE%84%E4%B8%AD%E7%9A%84%E5%8F%82%E6%95%B0"><span class="toc-number">1.4.</span> <span class="toc-text">1.4 通过@PathVariable获取路径中的参数</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-5-%E4%BD%BF%E7%94%A8-ModelAttribute%E6%B3%A8%E8%A7%A3%E8%8E%B7%E5%8F%96POST%E8%AF%B7%E6%B1%82%E7%9A%84FORM%E8%A1%A8%E5%8D%95%E6%95%B0%E6%8D%AE"><span class="toc-number">1.5.</span> <span class="toc-text">1.5 使用@ModelAttribute注解获取POST请求的FORM表单数据</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-6-%E7%94%A8%E6%B3%A8%E8%A7%A3-RequestParam%E7%BB%91%E5%AE%9A%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0%E5%88%B0%E6%96%B9%E6%B3%95%E5%85%A5%E5%8F%82"><span class="toc-number">1.6.</span> <span class="toc-text">1.6 用注解@RequestParam绑定请求参数到方法入参</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-7-%E7%94%A8%E6%B3%A8%E8%A7%A3-RequestBody%E7%BB%91%E5%AE%9A%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0%E5%88%B0%E6%96%B9%E6%B3%95%E5%85%A5%E5%8F%82-%E7%94%A8%E4%BA%8EPOST%E8%AF%B7%E6%B1%82"><span class="toc-number">1.7.</span> <span class="toc-text">1.7 用注解@RequestBody绑定请求参数到方法入参 用于POST请求</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-spring-boot%E7%9A%84-RequestParam%E5%92%8C-RequestBody%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">2.</span> <span class="toc-text">2. spring boot的@RequestParam和@RequestBody的区别</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-SpringBoot-%E4%B8%AD%E5%B8%B8%E7%94%A8%E6%B3%A8%E8%A7%A3-PathVaribale-RequestParam-GetMapping%E4%BB%8B%E7%BB%8D"><span class="toc-number">3.</span> <span class="toc-text">3. SpringBoot 中常用注解@PathVaribale&#x2F;@RequestParam&#x2F;@GetMapping介绍</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/02/08/Hexo%E6%96%B0%E5%BB%BA%E7%AC%AC%E4%B8%80%E7%AF%87%E5%8D%9A%E6%96%87/" title="Hexo新建第一篇博文"><img src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg1.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hexo新建第一篇博文"/></a><div class="content"><a class="title" href="/2022/02/08/Hexo%E6%96%B0%E5%BB%BA%E7%AC%AC%E4%B8%80%E7%AF%87%E5%8D%9A%E6%96%87/" title="Hexo新建第一篇博文">Hexo新建第一篇博文</a><time datetime="2022-02-07T16:00:00.000Z" title="发表于 2022-02-08 00:00:00">2022-02-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/12/06/1681-%E6%9C%80%E5%B0%8F%E4%B8%8D%E5%85%BC%E5%AE%B9%E6%80%A7/" title="最小不兼容性"><img src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg7.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="最小不兼容性"/></a><div class="content"><a class="title" href="/2021/12/06/1681-%E6%9C%80%E5%B0%8F%E4%B8%8D%E5%85%BC%E5%AE%B9%E6%80%A7/" title="最小不兼容性">最小不兼容性</a><time datetime="2021-12-05T16:00:00.000Z" title="发表于 2021-12-06 00:00:00">2021-12-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/12/17/714-%E4%B9%B0%E5%8D%96%E8%82%A1%E7%A5%A8%E7%9A%84%E6%9C%80%E4%BD%B3%E6%97%B6%E6%9C%BA%E5%90%AB%E6%89%8B%E7%BB%AD%E8%B4%B9/" title="买卖股票的最佳时机含手续费"><img src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg20.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="买卖股票的最佳时机含手续费"/></a><div class="content"><a class="title" href="/2020/12/17/714-%E4%B9%B0%E5%8D%96%E8%82%A1%E7%A5%A8%E7%9A%84%E6%9C%80%E4%BD%B3%E6%97%B6%E6%9C%BA%E5%90%AB%E6%89%8B%E7%BB%AD%E8%B4%B9/" title="买卖股票的最佳时机含手续费">买卖股票的最佳时机含手续费</a><time datetime="2020-12-16T16:00:00.000Z" title="发表于 2020-12-17 00:00:00">2020-12-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/12/15/AOP/" title="AOP学习"><img src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg10.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="AOP学习"/></a><div class="content"><a class="title" href="/2020/12/15/AOP/" title="AOP学习">AOP学习</a><time datetime="2020-12-14T16:00:00.000Z" title="发表于 2020-12-15 00:00:00">2020-12-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/12/15/docker%E5%91%BD%E4%BB%A4/" title="docker命令"><img src="https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg16.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="docker命令"/></a><div class="content"><a class="title" href="/2020/12/15/docker%E5%91%BD%E4%BB%A4/" title="docker命令">docker命令</a><time datetime="2020-12-14T16:00:00.000Z" title="发表于 2020-12-15 00:00:00">2020-12-15</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://cdn.jsdelivr.net/gh/FantasticCode2019/cdn/backgroud/bg11.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2022 By FantasticCode</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my <a href="https://yyj_challenged.gitee.io//">blog</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="聊天"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="algolia-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="search-wrap"><div id="algolia-search-input"></div><hr/><div id="algolia-search-results"><div id="algolia-hits"></div><div id="algolia-pagination"></div><div id="algolia-info"><div class="algolia-stats"></div><div class="algolia-poweredBy"></div></div></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page@5/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="https://cdn.jsdelivr.net/npm/algoliasearch@4/dist/algoliasearch-lite.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4/dist/instantsearch.production.min.js"></script><script src="/js/search/algolia.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function addGitalkSource () {
  const ele = document.createElement('link')
  ele.rel = 'stylesheet'
  ele.href= 'https://cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.css'
  document.getElementsByTagName('head')[0].appendChild(ele)
}

function loadGitalk () {
  function initGitalk () {
    var gitalk = new Gitalk(Object.assign({
      clientID: 'ea007ab939d0b7d664ea',
      clientSecret: '7f9f6bf9d107c6b3f99a5fe05e343ddd631adf82',
      repo: 'yyj_challenged',
      owner: 'FantasticCode2019',
      admin: ['FantasticCode2019'],
      id: '27f4f0b38acd388fa2dfb7f9e34fd8e4',
      updateCountCallback: commentCount
    },null))

    gitalk.render('gitalk-container')
  }

  if (typeof Gitalk === 'function') initGitalk()
  else {
    addGitalkSource()
    getScript('https://cdn.jsdelivr.net/npm/gitalk@latest/dist/gitalk.min.js').then(initGitalk)
  }
}

function commentCount(n){
  let isCommentCount = document.querySelector('#post-meta .gitalk-comment-count')
  if (isCommentCount) {
    isCommentCount.innerHTML= n
  }
}

if ('Gitalk' === 'Gitalk' || !true) {
  if (true) btf.loadComment(document.getElementById('gitalk-container'), loadGitalk)
  else loadGitalk()
} else {
  function loadOtherComment () {
    loadGitalk()
  }
}</script></div><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-nest.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>